﻿using System;
using System.Collections;

namespace TeamTasker.Utils
{
    /// <summary>
    /// Validation exception class.
    /// </summary>
    public class ValidationException : ArgumentException
    {
        public ValidationException(string message)
            : base(message)
        {
        }
    }

    /// <summary>
    /// Validation utilities.
    /// </summary>
    public class Validate
    {
        public static void NotBlank(string str, string message)
        {
            if (StringUtils.IsBlank(str))
            {
                throw new ValidationException(message);
            }
        }

        public static void Positive(int value, string message)
        {
            if (value <= 0)
            {
                throw new ValidationException(message);
            }
        }

        public static void Positive(long value, string message)
        {
            if (value <= 0)
            {
                throw new ValidationException(message);
            }
        }

        public static void NotEmpty(ICollection collection, string message)
        {
            if (collection == null || collection.Count == 0) 
            {
                throw new ValidationException(message);
            }
        }

        public static void Null(object obj, string message)
        {
            if (obj != null)
            {
                throw new ValidationException(message);
            }
        }

        public static void NotNull(object obj, string message)
        {
            if (obj == null)
            {
                throw new ValidationException(message);
            }
        }

        public static void True(bool value, string message)
        {
            if (value == false)
            {
                throw new ValidationException(message);
            }
        }

        public static void False(bool value, string message)
        {
            if (value)
            {
                throw new ValidationException(message);
            }
        }
    }
}
